package com.situ.student.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.situ.student.dao.IStudentDao;
import com.situ.student.dao.impl.StudentDaoJdbcImpl;
import com.situ.student.dao.impl.StudentDaoMemoryImpl;
import com.situ.student.entity.Student;
import com.situ.student.service.IStudentService;

public class StudentServiceImpl implements IStudentService{
	//private IStudentDao studentDao = new StudentDaoMemoryImpl();
	private IStudentDao studentDao = new StudentDaoJdbcImpl();

	@Override
	public boolean insert(Student student) {
		int count = studentDao.insert(student);
		return count == 1 ? true : false;
	}

	@Override
	public List<Student> list() {
		List<Student> list = studentDao.list();
		List<Student> copyList = new ArrayList<>();
		for (Student student : list) {
			student.setName("Java1807-" + student.getName());
			copyList.add(student);
		}
		return copyList;
		//return studentDao.list();
	}

	@Override
	public boolean deleteById(Integer id) {
		int count = studentDao.deleteById(id);
		return count == 1 ? true : false;
	}

}
